package cn.yunbamboos.media.zlm.client;

import cn.yunbamboos.media.zlm.api.ZLMApi;
import cn.yunbamboos.media.zlm.config.ZLMConfig;

/**
 * 调用ZLM客户端
 * */
public class ZLMClient {

    private int serverPort;
    private String dir;
    private String ffmpegPath;
    private String hookPath;
    private String mediaServerId;
    private String secret;
    private String schema = "http";
    private String ip;
    private int port = 20080;
    private int sslPort = 0;
    // 流媒体RTSP端口
    private int rtspPort = 20554;
    private int rtspSslPort = 0;
    // 流媒体RTMP端口
    private int rtmpPort = 21935;
    private int rtmpSslPort = 0;
    // rtp端口
    private int rtpPort = 0;
    // rtc端口
    private int rtcPort = 0;
    // srt
    private int srtPort = 0;

    private final ZLMConfig config = new ZLMConfig(this);
    private final ZLMApi api = new ZLMApi(this);

    // 服务状态
    private boolean started = false;
    // 上次心跳时间
    private long keepaliveTime;

    private ZLMClient(){

    }

    public int getServerPort() {
        return serverPort;
    }

    public String getDir() {
        return dir;
    }

    public String getFfmpegPath() {
        return ffmpegPath;
    }

    public String getHookPath() {
        return hookPath;
    }

    public String getMediaServerId() {
        return mediaServerId;
    }

    public String getSecret() {
        return secret;
    }

    public String getSchema() {
        return schema;
    }

    public String getIp() {
        return ip;
    }

    public int getPort() {
        return port;
    }

    public int getSslPort() {
        return sslPort;
    }

    public int getRtspPort() {
        return rtspPort;
    }

    public int getRtspSslPort() {
        return rtspSslPort;
    }

    public int getRtmpPort() {
        return rtmpPort;
    }

    public int getRtmpSslPort() {
        return rtmpSslPort;
    }

    public int getRtpPort() {
        return rtpPort;
    }

    public int getRtcPort() {
        return rtcPort;
    }

    public int getSrtPort() {
        return srtPort;
    }

    public ZLMConfig getConfig() {
        return config;
    }

    public ZLMApi getApi() {
        return api;
    }

    public boolean isStarted() {
        return started;
    }

    public void setStarted(boolean started) {
        this.started = started;
    }

    public long getKeepaliveTime() {
        return keepaliveTime;
    }

    public void setKeepaliveTime(long keepaliveTime) {
        this.keepaliveTime = keepaliveTime;
    }

    public static class Builder {

        private final ZLMClient client = new ZLMClient();

        public Builder serverPort(int serverPort) {
            client.serverPort = serverPort;
            return this;
        }

        public Builder dir(String dir) {
            client.dir = dir;
            return this;
        }
        public Builder ffmpegPath(String ffmpegPath) {
            client.ffmpegPath = ffmpegPath;
            return this;
        }
        public Builder hookPath(String hookPath) {
            client.hookPath = hookPath;
            return this;
        }
        public Builder mediaServerId(String mediaServerId) {
            client.mediaServerId = mediaServerId;
            return this;
        }
        public Builder secret(String secret) {
            client.secret = secret;
            return this;
        }
        public Builder schema(String schema) {
            client.schema = schema;
            return this;
        }
        public Builder ip(String ip) {
            client.ip = ip;
            return this;
        }
        public Builder port(int port) {
            client.port = port;
            return this;
        }
        public Builder sslPort(int sslPort) {
            client.sslPort = sslPort;
            return this;
        }
        public Builder rtspPort(int rtspPort) {
            client.rtspPort = rtspPort;
            return this;
        }
        public Builder rtspSslPort(int rtspSslPort) {
            client.rtspSslPort = rtspSslPort;
            return this;
        }
        public Builder rtmpPort(int rtmpPort) {
            client.rtmpPort = rtmpPort;
            return this;
        }
        public Builder rtmpSslPort(int rtmpSslPort) {
            client.rtmpSslPort = rtmpSslPort;
            return this;
        }
        public Builder rtpPort(int rtpPort) {
            client.rtpPort = rtpPort;
            return this;
        }
        public Builder rtcPort(int rtcPort) {
            client.rtcPort = rtcPort;
            return this;
        }
        public Builder srtPort(int srtPort) {
            client.srtPort = srtPort;
            return this;
        }

        public ZLMClient build(){
            return client;
        }
    }
}
